package com.lancoo.edu.platform.operation.backupRestore.controller;

import com.lancoo.edu.platform.operation.backupRestore.domain.bo.UpdateTaskBo;
import com.lancoo.edu.platform.operation.backupRestore.domain.bo.UpdateTaskTurnBo;
import com.lancoo.edu.platform.operation.backupRestore.service.bo.BrScheduleTaskBoService;
import com.lancoo.edu.platform.operation.commons.annotation.CheckToken;
import com.lancoo.edu.platform.operation.commons.controller.base.BaseResultController;
import com.lancoo.edu.platform.operation.commons.dto.BaseResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author lzh
 */
@RestController
@RequestMapping("/api/backupRestore/scheduleTask")
@AllArgsConstructor
public class BrScheduleTaskController extends BaseResultController {

    private final BrScheduleTaskBoService brScheduleTaskBoService;


    /**
     * 获取定时任务
     *
     * @param taskMethod 定时任务方法
     * @return 定时任务信息
     */
    @GetMapping("/getScheduleTask")
    @CheckToken
    public BaseResult getScheduleTask(@Valid @NotBlank(message = "taskMethod不能为空") String taskMethod) {
        return success(brScheduleTaskBoService.getScheduleTask(taskMethod));
    }

    /**
     * 更新定时任务
     *
     * @param updateTaskBo 更新定时任务接收实体类
     * @return 返回成功
     */
    @PostMapping("/updateTask")
    @CheckToken
    public BaseResult updateTask(@Valid @RequestBody UpdateTaskBo updateTaskBo) {
        brScheduleTaskBoService.updateTask(updateTaskBo);
        return success();
    }

    /**
     * 更新定时任务开关
     *
     * @param updateTaskTurnBo 更新定时任务开关接收实体类
     * @return 返回成功
     */
    @PostMapping("/updateTaskTurnBo")
    @CheckToken
    public BaseResult updateTaskTurnBo(@Valid @RequestBody UpdateTaskTurnBo updateTaskTurnBo) {
        brScheduleTaskBoService.updateTaskTurnBo(updateTaskTurnBo);
        return success();
    }
}
